package projectManagement;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Dimension;
import javax.swing.JButton;

import java.awt.Color;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ClientProfilePictureSelection extends JPanel {
	GridBagConstraints gbc;
	JButton pic1, pic2, pic3, pic4, pic5, pic6, pic7, pic8, pic9, pic10, pic11, btnOk;
	Action ac = new Action();
	JFrame f;
	
	/**
	 * Create the panel.
	 */
	public ClientProfilePictureSelection() {
		setPreferredSize(new Dimension(530, 247));
		setBackground(new Color(72, 209, 204));
		setOpaque(true);
		setLayout(new GridBagLayout());
		gbc = new GridBagConstraints();
		
		pic1 = updateButton("profile/pic1.png");
		gbc.insets = new Insets(0, 0, 5, 5);
		gbc.gridx = 1;
		gbc.gridy = 1;
		pic1.addActionListener(ac);
		add(pic1, gbc);
		
		pic2 = updateButton("profile/pic2.png");
		gbc.insets = new Insets(0, 0, 5, 5);
		gbc.gridx = 2;
		gbc.gridy = 1;
		pic2.addActionListener(ac);
		add(pic2, gbc);
		
		pic3 = updateButton("profile/pic3.png");
		gbc.insets = new Insets(0, 0, 5, 5);
		gbc.gridx = 3;
		gbc.gridy = 1;
		pic3.addActionListener(ac);
		add(pic3, gbc);
		
		pic4 = updateButton("profile/pic4.png");
		gbc.insets = new Insets(0, 0, 5, 5);
		gbc.gridx = 4;
		gbc.gridy = 1;
		pic4.addActionListener(ac);
		add(pic4, gbc);
		
		pic5 = updateButton("profile/pic5.png");
		gbc.insets = new Insets(0, 0, 5, 0);
		gbc.gridx = 5;
		gbc.gridy = 1;
		pic5.addActionListener(ac);
		add(pic5, gbc);
		
		pic6 = updateButton("profile/pic6.png");
		gbc.insets = new Insets(0, 0, 0, 5);
		gbc.gridx = 1;
		gbc.gridy = 3;
		pic6.addActionListener(ac);
		add(pic6, gbc);
		
		pic7 = updateButton("profile/pic7.png");
		gbc.insets = new Insets(0, 0, 0, 5);
		gbc.gridx = 2;
		gbc.gridy = 3;
		pic7.addActionListener(ac);
		add(pic7, gbc);
		
		pic8 = updateButton("profile/pic8.png");
		gbc.insets = new Insets(0, 0, 0, 5);
		gbc.gridx = 3;
		gbc.gridy = 3;
		pic8.addActionListener(ac);
		add(pic8, gbc);
		
		pic9 = updateButton("profile/pic9.png");
		gbc.insets = new Insets(0, 0, 0, 5);
		gbc.gridx = 4;
		gbc.gridy = 3;
		pic9.addActionListener(ac);
		add(pic9, gbc);
		
		pic10 = updateButton("profile/pic10.png");
		gbc.gridx = 5;
		gbc.gridy = 3;
		pic10.addActionListener(ac);
		add(pic10, gbc);
		
		pic11 = updateButton("profile/profile.png");
		gbc.gridx = 3;
		gbc.gridy = 4;
		pic11.addActionListener(ac);
		add(pic11, gbc);
		
		btnOk = new JButton("Ok");
		gbc.gridx = 1;
		gbc.gridy = 4;
		btnOk.addActionListener(ac);
		add(btnOk, gbc);
	
		
		f = new JFrame("Choose Picture");
		f.add(this);
		f.pack();
		f.setLocationRelativeTo(null);
		f.setVisible(true);
		f.setResizable(true);
		f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);

	}
	
	public class Action implements ActionListener{

		@SuppressWarnings("deprecation")
		@Override
		public void actionPerformed(ActionEvent btn) {
			JButton action = (JButton) btn.getSource();
			
			if(action.equals(pic1)){
				ProfileButton.picture = "profile/pic1.png";
				ClientGUI.updateProfile("profile/pic1.png");
			}
			if(action.equals(pic2)){
				ProfileButton.picture = "profile/pic2.png";
				ClientGUI.updateProfile("profile/pic2.png");
			}
			if(action.equals(pic3)){
				ProfileButton.picture = "profile/pic3.png";
				ClientGUI.updateProfile("profile/pic3.png");
			}
			if(action.equals(pic4)){
				ProfileButton.picture = "profile/pic4.png";
				ClientGUI.updateProfile("profile/pic4.png");
			}
			if(action.equals(pic5)){
				ProfileButton.picture = "profile/pic5.png";
				ClientGUI.updateProfile("profile/pic5.png");
			}
			if(action.equals(pic6)){
				ProfileButton.picture = "profile/pic6.png";
				ClientGUI.updateProfile("profile/pic6.png");
			}
			if(action.equals(pic7)){
				ProfileButton.picture = "profile/pic7.png";
				ClientGUI.updateProfile("profile/pic7.png");
			}
			if(action.equals(pic8)){
				ProfileButton.picture = "profile/pic8.png";
				ClientGUI.updateProfile("profile/pic8.png");
			}
			if(action.equals(pic9)){
				ProfileButton.picture = "profile/pic9.png";
				ClientGUI.updateProfile("profile/pic9.png");
			}
			if(action.equals(pic10)){
				ProfileButton.picture = "profile/pic10.png";
				ClientGUI.updateProfile("profile/pic10.png");
			}
			if(action.equals(pic11)){
				ProfileButton.picture = "profile/profile.png";
				ClientGUI.updateProfile("profile/profile.png");
			}
			if(action.equals(btnOk)){
				f.hide();
			}
			
		}
		
	}
	
	
	public JButton updateButton(String icon){
		 ProfileButton.picture = icon;
		 ProfileButton button = new ProfileButton();
		
		 return button;
	}
}

